import tagsViewStore from "../store/modules/tags-view";
import TagsView from "./tags-view";
import ListContainer from "./list-container";
import ShowContainer from "./show-container";
import LayoutContainer from "./layout-container";
import layoutMenu from "../store/modules/layout-menu";
import LayoutMenu from "./layout-menu";
import YuiTagsTab from "./yui-tags-tab";
import YuiLayoutTabs from "./yui-layout-tabs";
// 存储组件列表
const components = [
  TagsView,
  ListContainer,
  ShowContainer,
  LayoutContainer,
  LayoutMenu,
  YuiTagsTab,
  YuiLayoutTabs
];

// 定义 install 方法，接收 Vue 作为参数。如果使用 use 注册插件，则所有的组件都将被注册
const install = function(Vue, opts = {}) {
  if (!opts.store) {
    console.error("Please provide a store!");
  }
  //动态注册store;
  opts.store.registerModule("tagsView", tagsViewStore);
  opts.store.registerModule("layoutMenu", layoutMenu);

  // 判断是否安装
  if (install.installed) return;
  // 遍历注册全局组件
  components.map(component => {
    Vue.component(component.name, component);
  });
};

// 判断是否是直接引入文件
if (typeof window !== "undefined" && window.Vue) {
  install(window.Vue);
}

export default {
  // 导出的对象必须具有 install，才能被 Vue.use() 方法安装
  install,
  // 以下是具体的组件列表
  TagsView,
  ListContainer,
  ShowContainer,
  YuiTagsTab,
  YuiLayoutTabs
};
